from selenium import webdriver
from selenium.webdriver.common.by import By

class HOSPITAL:
    def __init__(self, driver):
        self.driver = driver
        self.driver.maximize_window()
        self.driver.implicitly_wait(15)
    def get_url(self, url):
        self.driver.get(url)


    def seacher(self, str_):
        s1 = self.driver.find_element(By.XPATH, "//*[@id='header']/div/div/div/form/input[2]")
        s1.clear()
        s1.send_keys(str_)

    def click_seacher(self):
        self.driver.find_element(By.XPATH, "//*[@id='header']/div/div/div/form/button").click()

    def exchange_windows(self):
        self.driver.switch_to.window(driver.window_handles[-1])
    def click_(self):
        self.driver.find_element(By.XPATH,"/html/body/div[4]/ul/li[1]/div[1]/h5/a").click()

    def assert_text(self):
        test1 = self.driver.find_element(By.XPATH, "/html/body/div[3]/div/div/article/div[2]/p[1]/span[1]").text
        print(test1)
        assert "毕节市第一人民医院即将进行高值医用耗材网上阳光平台议价采购工作" in test1

    def qiut_(self):
        self.driver.quit()

if __name__ == '__main__':
    driver = webdriver.Chrome()
    s1 = HOSPITAL(driver)
    s1.get_url("http://www.bjhospital.net/")
    s1.seacher("骨科")
    s1.click_seacher()
    s1.click_()
    s1.exchange_windows()
    s1.assert_text()
    s1.qiut_()
